package com.yuanfeng.activity.controller;

import com.yuanfeng.activity.dto.JoinVoucherActivityDTO;
import com.yuanfeng.activity.dto.VoucherTemplateUpdateDTO;
import com.yuanfeng.commoms.exception.BizCodeEnume;
import com.yuanfeng.commoms.util.ResponseResult;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @ClassName ActivityVoucherTemplateController
 * @Description 代金券模版
 * @Author cf
 * @Date 2023/7/4 11:09
 * @Version 1.0
 */
@RestController
@RequestMapping("/activity/voucher/template")
public class ActivityVoucherTemplateController extends BaseController{



    /**
     * 商家后台：查询优惠券信息
     *
     */
    @PostMapping("/select")
    public ResponseResult selectVoucherTemp(@RequestBody Map<String, Object> paraMap) {
        ResponseResult result = activityVoucherTemplateService.selectVoucherTemp(paraMap);
        return result;
    }

    /**
     * 商家后台：删除代金券信息 1.1将删除代金券改为修改代金券状态
     */
    @PostMapping("/delete")
    public ResponseResult deleteVoucherTemp(@RequestBody Map<String, String> paraMap) {
        ResponseResult result = activityVoucherTemplateService.deleteVoucherTemp(paraMap);
        return result;
    }

    /**
     * 商家后台：插入代金券模板
     *
     */
    @GlobalTransactional
    @PostMapping("/insert")
    public ResponseResult insertVoucherTemp(@RequestBody VoucherTemplateUpdateDTO param) {
        // 校验参数
        if (param.getVoucherTLimit().compareTo(param.getVoucherTPrice()) < 0) {
            return ResponseResult.fail(BizCodeEnume.INCORRECT_AMOUNT);
        }
        ResponseResult result = activityVoucherTemplateService.insertVoucherTemp(param);
        return result;
    }

    /**
     * 查询可报名的优惠券活动
     * @return
     */
    @PostMapping("/query/list")
    public ResponseResult queryPlatformVoucherList(@RequestBody Map<String,String> param) {
        ResponseResult result=activityVoucherTemplateService.queryPlatformVoucherList(param);
        return result;
    }

    /**
     * 商家参加优惠券活动
     * @param param
     * @return
     */
    @PostMapping("/update")
    public ResponseResult joinVoucherActivity(@RequestBody JoinVoucherActivityDTO param) {
        ResponseResult result=activityVoucherTemplateService.joinVoucherActivity(param);
        return result;
    }

    /**
     * 优惠商品
     * @param param
     * @return
     */
    @PostMapping("/query")
    public ResponseResult queryVoucherGoods(@RequestBody JoinVoucherActivityDTO param) {
        ResponseResult result=activityVoucherTemplateService.queryVoucherGoods(param);
        return result;
    }

    /**
     * 平删除 店铺优惠券
     *
     * @param paraMap
     * @return
     */
    @PostMapping("/platform/delete")
    public ResponseResult deleteSalesPromotionVoucher(@RequestBody Map<String, String> paraMap) {
        ResponseResult result=activityVoucherTemplateService.deleteSalesPromotionVoucher(paraMap);
        return result;

    }

    /**
     * 平台查询 店铺优惠券详情
     *
     * @param paraMap
     * @return
     */
    @PostMapping("/platform/detail")
    public ResponseResult salesPromotionVoucherDetail(@RequestBody Map<String, Object> paraMap) {
        ResponseResult result=activityVoucherTemplateService.salesPromotionVoucherDetail(paraMap);
        return result;
    }


    /**
     * 平台查询 店铺优惠券列表
     *
     * @param paraMap
     * @return
     */
    @PostMapping("/platform/list")
    public ResponseResult salesPromotionVoucherList(@RequestBody Map<String, Object> paraMap) {
        ResponseResult result=activityVoucherTemplateService.salesPromotionVoucherList(paraMap);
        return result;
    }


    /**
     * 平台修改 店铺优惠券修改
     *
     * @param paraMap
     * @return
     */
    @PostMapping("/platform/update")
    public ResponseResult salesPromotionVoucherUpdate(@RequestBody Map<String, Object> paraMap) {
        ResponseResult result=activityVoucherTemplateService.salesPromotionVoucherUpdate(paraMap);
        return result;
    }
}
